package cn.wolfcode.wms.web.controller;

import cn.wolfcode.wms.annotation.RequriedPermission;
import cn.wolfcode.wms.domain.Permission;
import cn.wolfcode.wms.util.AjaxResult;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;
    @RequriedPermission("权限列表")
    @RequestMapping("query")
    public String query(Model model, @ModelAttribute("qo")QueryObject qo){
        PageInfo<Permission> result = permissionService.query(qo);
        model.addAttribute("result",result);
        return "permission/list";
    }
    @RequriedPermission("权限删除")
    @RequestMapping("delete")
    @ResponseBody
    public AjaxResult delete(Long id){
        if (id != null){
            permissionService.delete(id);
        }
        return new AjaxResult();
    }
    @RequriedPermission("权限加载")
    @RequestMapping("reload")
    @ResponseBody
    public AjaxResult reload(){
        permissionService.reload();
        return new AjaxResult();
    }
}
